<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts' // echarts theme
import resize from '@/framework/utils/mixins/resize'
import { pieData } from '@/framework/api/authenticationCenter/index'

require('echarts/theme/macarons')

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null,
      pieData: []
    }
  },
  mounted() {
    // this.$nextTick(() => {
    //   this.getData()
    // })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      pieData().then((res) => {
        if (res.sucess) {
          this.chart = echarts.init(this.$el, 'macarons')
          this.chart.setOption({
            title: {
              text: '各认证方式占比',
              x: 'left',
              y: 'top',
              textStyle: {
                color: '#131314',
                fontSize: '16'
              }
            },
            tooltip: {
              trigger: 'item',
              formatter: '{a} <br/>{b} : {c} ({d}%)'
            },
            legend: {
              show: true,
              left: 'center',
              bottom: '0',
              icon: 'circle', // 设置图例为圆形
              itemHeight: 10, // 图例icon高度
              itemWidth: 10, // 图例icon宽度
              data: ['帐密认证', '动态验证码', 'CAS认证']
            },
            color: ['#86DF6C', '#3461FF', '#21CCFF'],
            series: [
              {
                name: '认证方式占比',
                type: 'pie',
                radius: '50%',
                // data: [
                //   // { value: 24, name: '帐密认证' },
                //   // { value: 40, name: '动态验证码' },
                //   // { value: 36, name: 'CAS认证' }
                // ],
                data: this.pieData,
                animationEasing: 'cubicInOut',
                animationDuration: 2600,
                label: {
                  show: true,
                  formatter: '{b} \n{d}%, {c}人',
                  textStyle: {
                    color: '#606266'
                  }
                }

              }
            ]
          })
        }
      })
    }

  }
}
</script>
